//左右箭头滚动
if($(".slideMenu").length!=0){
    var slidecon = $(".slideMenu");
    var oc = $(slidecon).find("li.active"),
        oclength = $(slidecon).find("li").length;
    var sld=function(){var slideBtnWidth=document.querySelector(".slideMenuCon>span").scrollWidth*2;
        slidecon.animate({scrollLeft:oc[0].offsetLeft-(oc[0].offsetWidth/2)-slideBtnWidth},500);}
    $(function(){
        sld();
    });
}
var slideMenuStBar = function (tag) {
    var oc = $(slidecon).find("li.active");
    if (tag == "next") {
        if (oc.index() < oclength-1) {
            oc.next().find("a")[0].click();
        }
    } else if (tag == "pver") {
        if (oc.index() > 0) {
            oc.prev().find("a")[0].click();
        }
    }
  
};
//顶部标签
var hammerInit = function (ele) {
    var mySlide = new Hammer(ele, {
        multiUser: true
    });
    mySlide.get('pan').set({
        direction: Hammer.DIRECTION_ALL
    }); //横向
    mySlide.get('swipe').set({
        direction: Hammer.DIRECTION_ALL
    }); //纵向
    mySlide.get('pinch').set({
        enable: true
    }); //多点触摸
    mySlide.get('rotate').set({
        enable: true
    }); //多点触摸
    return mySlide;
};
Element.prototype.getStyle = function (attr) {
    if (this.currentStyle) {
        return parseFloat(this.currentStyle[attr]);
    } else {
        if (this !== window) {
            return parseFloat(getComputedStyle(this, false)[attr]);
        };
    }
}
var slideMenu = {
    OSN: {
        timer: null
    },
    slide: function (j, c, g) {
        clearInterval(slideMenu.OSN.timer);
        var i = 0;
        slideMenu.OSN.timer = setInterval(function () {
                var a = Math.exp(-g * i) * c;
                j[0].scrollLeft += a;
                if (Math.abs(a) < 8) {
                    if (Math.abs(a) <= 1.5) {
                        clearInterval(slideMenu.OSN.timer)
                    }
                }
                i++
            },
            16);
    },
    init: function (con, json) {
        con.style.overflow = "hidden";
        this.OSN.thisMenu = con.children[0];
        this.OSN.thisLi = this.OSN.thisMenu.children;
        this.OSN.init = this.init;
        this.OSN.timer = null;
        //            this.OSN.Next = 0;
        this.OSN.st = 0;
        this.OSN.staw = [];
        this.OSN.slideE = hammerInit(this.OSN.thisMenu);
        this.OSN.slide = this.slide;
        for (var i = 0; i < this.OSN.thisLi.length; i++) {
            //                this.OSN.thisLi[i].style.width = json.liWidth + "px";
        };
        var margin = {};
        margin.l = !this.OSN.thisLi[0].getStyle("margin-left") ? 0 : this.OSN.thisLi[0].getStyle("margin-left");
        margin.r = !this.OSN.thisLi[0].getStyle("margin-right") ? 0 : this.OSN.thisLi[0].getStyle("margin-right");
        this.OSN.thisMenu.style.width = (this.OSN.thisLi[0].offsetWidth + margin.l + margin.r) * this.OSN.thisLi.length + "px";
    },
    execute: function (json) {
        slideMenu.init(this, json);
        if (this.scrollWidth > window.innerWidth) {
            var slideE = slideMenu.OSN.slideE;
            slideE.on("pan swipe", function (ev) {
                ev.preventDefault();
                var self = $($(slideE)[0].element).parent();
                if (ev.isFinal !== true) {
                    //                        var speed = !!json.speed && json.speed >= 8 && json.speed <= 30 && typeof json.speed === "number" ? json.speed : 8;
                    slideMenu.OSN.staw.push(ev.deltaX);
                    slideMenu.OSN.staw.splice(0, slideMenu.OSN.staw.length - 2);
                    slideMenu.OSN.st = slideMenu.OSN.staw[0];
                    self[0].scrollLeft += (slideMenu.OSN.st - ev.deltaX);
                    clearInterval(slideMenu.OSN.timer);
                } else {
                    slideMenu.OSN.slide(self, slideMenu.OSN.st - ev.deltaX, 0.03);
                    slideMenu.OSN.staw = [];
                }
            });
        }
    },
    close: function () {
        var slideE = slideMenu.OSN.slideE;
        slideE.off("pan swipe");
    }
};

Element.prototype.slideMenuSt = slideMenu.execute;
Element.prototype.slideMenuEd = slideMenu.close;